﻿/*
   Copyright 2012 Dmitry Bratus

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/

using System.Runtime.Serialization;

namespace Flower.Services
{
    /// <summary>
    /// The directory service fault.
    /// 
    /// The directory service throws faults of this type when preconditions are not satisfied. 
    /// 
    /// The directory implementations may not handle all unexpected
    /// exceptions (like NullReferenceException, for example), but the default host implementation
    /// wraps the directory service with the exception shield transforming all unhandled exceptions to
    /// the faults with code ServerError.
    /// </summary>
    [DataContract(Namespace = XmlNamespace.Directory)]
    public class DirectoryFault
    {
        /// <summary>
        /// The code by which the error conditions can be distinguished.
        /// </summary>
        [DataMember]
        public DirectoryFaultCode Code { get; set; }
    }

    /// <summary>
    /// The directory service fault code.
    /// </summary>
    [DataContract(Namespace = XmlNamespace.Directory)]
    public enum DirectoryFaultCode
    {
        /// <summary>
        /// An argument of a service call is empty or has invalid value.
        /// </summary>
        [EnumMember]
        InvalidArgument,

        /// <summary>
        /// The operation is not permitted for the calling identity.
        /// </summary>
        [EnumMember]
        AccessDenied,

        /// <summary>
        /// An id of a directory entry has invalid format.
        /// </summary>
        [EnumMember]
        InvalidIdFormat,

        /// <summary>
        /// The directory entry whose id or path is specified doesn't exist.
        /// </summary>
        [EnumMember]
        EntryNotFound,

        /// <summary>
        /// A parent entry already has a child with the same name.
        /// </summary>
        [EnumMember]
        NameCollision,

        /// <summary>
        /// Syntax or runtime error occurred in a script.
        /// </summary>
        [EnumMember]
        ScriptError,

        /// <summary>
        /// Internal server error.
        /// </summary>
        [EnumMember]
        ServerError
    }
}
